﻿using System;
using System.Data;
using DataAccessObject;
using EntityObject;
using SharedLibraries;
using SharedLibraries.Constants;
using ThangNM_LIB.FUNC;

namespace ThangNM
{
    public partial class Download : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var master = Master as ThangNM.PublicInterface.Home_New;
            try
            {
                if (!IsPostBack)
                {
                    if (Request.QueryString[QueryString.file] != null)
                    {
                        FileEO _FileEO = new FileEO();
                        DataSet dsFile = null;
                        Int32 iUID = 0;
                        if (Int32.TryParse(StringEx.Trim(StringEx.Trim(Request.QueryString[QueryString.file])), out iUID))
                        {
                            _FileEO.PK_iFileID = iUID;
                            dsFile = (new FileDAO()).SelectBy_PK_iFileID(_FileEO.PK_iFileID);
                        }
                        if (DataTableEx.DataTable_OK(null, dsFile, 0) == false)
                        {
                            Commons.setRedirect(Page, null);
                            return;
                        }
                        _FileEO = (new FileDAO()).FileDO(dsFile.Tables[0]);
                        if (_FileEO == null)
                        {
                            Commons.setRedirect(Page, null);
                            return;
                        }
                        if (!StringEx.Compare(Request.RawUrl.Substring(1), _FileEO.sUrlRewrite))
                        {
                            Commons.setRedirect(Page, _FileEO.sUrlRewrite);
                            return;
                        }
                        //DataTable dtOther = null;
                        //if (DataTableEx.DataTable_OK(null, dsFile, 1))
                        //    dtOther = dsFile.Tables[1];
                        Commons.setSEO_ON_PAGE(Page, _FileEO, this.GetType());
                        ArticleUC1.BindData_File(_FileEO);
                        ArticleUC1.BindData_Common(null, null, _FileEO, true);
                    }
                }
            }
            catch (Exception ex)
            {
                if (master != null)
                    master.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
            }
        }
    }
}